﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;
using System.Data;
namespace TranTekBE.KPI_NhanSu
{
    public partial class WebForm1 : PagePopUp
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load JS
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "LoadJS", "LoadJS();", true);
            if (!IsPostBack)
            {
                lbUserLogin.Text = UserInfo.LastName + UserInfo.FirstName;
                FunctionsUtils.GetDropListStore(droplist_cua_hang_lam_viec);

                ViewState["IDLich"]  = FunctionsUtils.GetValueStringFromQueryString("idevent", "0");
                if (Convert.ToInt32(ViewState["IDLich"].ToString()) > 0)
                {
                    string sql = "select * from tbl_LichLamViec where ID_LICH_LAM_VIEC = '" + ViewState["IDLich"].ToString() + "'";
                    DataSet ds = FunctionsUtils.Database2.ExecuteQuery(sql);
                    if (!FunctionsUtils.IsNullOrEmpty(ds))
                    {
                        droplist_cua_hang_lam_viec.SelectedValue = ds.Tables[0].Rows[0]["CUA_HANG_DANG_LAM_VIEC"].ToString();
                        try
                        {
                            lbNgayDaXep.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["NGAY_THEM_VAO"].ToString()).ToShortDateString();
                        }
                        catch { }
                        radio_btn_ca.SelectedValue = ds.Tables[0].Rows[0]["CA_LAM_VIEC"].ToString();
                    }

                }
            }



        }

        protected void btnAddYeuCau_Click(object sender, EventArgs e)
        {
            string name_user = UserInfo.UserName;
            string id_user = UserInfo.UserID;
            string cua_hang_dang_lam_viec = droplist_cua_hang_lam_viec.SelectedValue.ToString();
            int ca_lam_viec = Convert.ToInt32(radio_btn_ca.SelectedValue.ToString());
            DateTime ngay_dang_lam_viec = Convert.ToDateTime(lbNgayDaXep.Text.ToString());
            string ly_do = txtareaLyDo.Text;
            string sql_add_yeu_cau_chuyen_ca = @"
                                    INSERT INTO tbl_YeuCauChuyenCa
                                    (ID_USER,NAME_USER,CA_DANG_LAM,NGAY_DANG_LAM,CUA_HANG_DANG_LAM,LY_DO,TRANG_THAI,NGAY_GUI_YEU_CAU)
                                    VALUES
                                    ('" + id_user + "','" + name_user + "',"
                                                + ca_lam_viec + ",'"
                                                + lbNgayDaXep.Text.ToString() + "','"
                                                + cua_hang_dang_lam_viec + "',N'"
                                                + ly_do + "',N'Chưa xử lý','"+DateTime.Now+"'"
                                                + ")";
            try
            {
                // Insert yêu cầu chuyển ca
                FunctionsUtils.Database2.ExecuteNonQuery(sql_add_yeu_cau_chuyen_ca);
                Page page = (HttpContext.Current.Handler as Page);
                if (page != null)
                {
                    //page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "key", "alert('Bạn đã đánh giá thành công!')", true);
                    Response.Write("<script>alert('Bạn đã gửi yêu cầu thành công!');</script>");
                    ClosePopup(false);
                }
            }
            catch (Exception ex)
            {
                ltrErr.Text = ex.Message;
                ltrErr.ForeColor = System.Drawing.Color.Red;
            }


        }
        
    }
}